package com.shanghaionstar.mro.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shanghaionstar.R;

/**
 * Created by kai zhang on 2015/10/16 13:28.
 */
public class MrOHelpHeader extends RelativeLayout {
    private Context context;
    private View container;
    private ImageView number;
    private TextView title;
    private TextView detail_message;
    private TypedArray typedArray;

    public MrOHelpHeader(Context context) {
        this(context, null);
    }

    public MrOHelpHeader(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MrOHelpHeader(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        typedArray = context.obtainStyledAttributes(attrs, R.styleable.MrOHelpHeader);
        initView();
    }

    private void initView() {
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        container = View.inflate(context, R.layout.mro_help_single_header, this);
        number = (ImageView) container.findViewById(R.id.mro_help_single_title_num);
        title = (TextView) container.findViewById(R.id.mro_help_single_title);
        detail_message = (TextView) container.findViewById(R.id.mro_help_detail_text_message);
        int resourceId = typedArray.getResourceId(
                R.styleable.MrOHelpHeader_title_number, 0);
        if (resourceId > 0)
            number.setImageResource(resourceId);
        String titleStr = typedArray.getString(R.styleable.MrOHelpHeader_title_mro);
        if (titleStr != null)
            title.setText(titleStr);
        String detailStr = typedArray.getString(R.styleable.MrOHelpHeader_title_detail);
        if (detailStr != null)
            detail_message.setText(detailStr);
    }
}
